package com.drinks.yiniang.adapter.user.wish;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseViewHolder;
import com.drinks.yiniang.R;
import com.drinks.yiniang.adapter.base.BaseQuickRCVAdapter;
import com.drinks.yiniang.entity.community.CommunityHotJson;
import com.drinks.yiniang.entity.user.wish.DrinksWishJson;
import com.drinks.yiniang.utils.GlideUtils;
import com.hansen.library.Constants;
import com.hansen.library.ui.widget.image.CircleImageView;
import com.hansen.library.ui.widget.image.RatioRoundImageView;
import com.hansen.library.utils.StringUtils;

import java.util.List;

/**
 * 酒单列表adapter
 *
 * @author han
 * @date 2019/8/30
 */
public class DrinksWishAdapter extends BaseQuickRCVAdapter<DrinksWishJson.DrinksWishList, BaseViewHolder> {

    private Drawable mLikeNormalDrawable;
    private Drawable mLikeFocusDrawable;

    public DrinksWishAdapter(Context mContext, @Nullable List<DrinksWishJson.DrinksWishList> data) {
        super(R.layout.item_drinks_wish_list, data);

        mLikeNormalDrawable = ContextCompat.getDrawable(mContext, R.mipmap.icon_community_likes_mall_n);
        mLikeFocusDrawable = ContextCompat.getDrawable(mContext, R.mipmap.icon_community_likes_mall_p);
    }

    @Override
    protected void convert(BaseViewHolder helper, DrinksWishJson.DrinksWishList item) {
        //封面
        GlideUtils.loadSquareImage(mContext, (RatioRoundImageView) helper.getView(R.id.iv_drinks_wish_cover), item.getCover_url());
        //头像
        GlideUtils.loadAvatar(mContext, (CircleImageView) helper.getView(R.id.iv_drinks_wish_avatar), item.getAvatar());
        //昵称
        helper.setText(R.id.tv_drinks_wish_nickname, item.getUsername());
        //点赞数量
        setLikeData((TextView) helper.getView(R.id.tv_drinks_wish_follows_num), item);
        //内容
        helper.setText(R.id.tv_drinks_wish_info, item.getTitle());

//        if (true) {
//            helper.setGone(R.id.tv_drinks_wish_from, true);
//        } else {
//            helper.setGone(R.id.tv_drinks_wish_from, false);
//        }

        helper.addOnClickListener(R.id.tv_drinks_wish_follows_num);
    }

    //点赞
    private void setLikeData(TextView tvLike, DrinksWishJson.DrinksWishList item) {
        tvLike.setText(StringUtils.getNullEmptyConvertZero(item.getLike_count()));
        tvLike.setCompoundDrawablesWithIntrinsicBounds(Constants.STATUS_GLOBAL_YES.equals(item.getIs_like()) ? mLikeFocusDrawable : mLikeNormalDrawable, null, null, null);
    }
}
